<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    function intersection(arr1, arr2) {
        let set = new Set(arr1)
        let ans = new Set()
        for (let i = 0; i < arr2.length; i++) {
            set.has(arr2[i]) && ans.add(arr2[i])
        }
        return Array.from(ans)
    }
    console.log(intersection([1, 2, 3], [1, 2, 4, 5, 6]))
</script>